<template>
	<view v-if="userData">
		<input type="text" :disabled="userData.bankName?true:false" v-model="bankDAO.bankName" placeholder="请输入银行名" placeholder-class="phl" class="inp">
		<input type="text" :disabled="userData.bankName?true:false" v-model="bankDAO.accountNumber	" placeholder="请输入银行卡号" placeholder-class="phl" class="inp">
		<input type="text" :disabled="userData.bankName?true:false" v-model="bankDAO.name" placeholder="请输入持卡人姓名" placeholder-class="phl" class="inp">
		<input type="number" maxlength="6" v-if="!userData.bankName" v-model="bankDAO.password" placeholder="请输入交易密码" placeholder-class="phl" class="inp">
		<text class="title">绑定后不可修改,银行信息用于现金充值或提现</text>
		<button class="btn" v-if="!userData.bankName" @click="submit">确定</button>
	</view>
</template>

<script setup>
	import {
		user,
		setBankInfo
	} from '@/util/api.js'
	import {
		ref
	} from "vue";
	import {
		onShow
	} from '@dcloudio/uni-app'
	onShow(()=>{
		getUser()
	})
	const bankDAO = ref({
		accountNumber:"",
		bankName:"",
		name:"",
		password:""
	})
	const userData = ref()
	// 获取当前登录用户信息
	const getUser = async () => {
		const result = await user()
		console.log(result)
		if (result.code == 200) {
			
			bankDAO.value.bankName = result.data.bankName
			bankDAO.value.name = result.data.name
			bankDAO.value.accountNumber = result.data.accountNumber
			userData.value = result.data
		} else {
			userData.value = null
		}
	}
	const submit = async() =>{
		if(!bankDAO.value.bankName){
			uni.showModal({
				title:"提示",
				content:"请输入银行名",
				showCancel:false
			})
			return false;
		}
		if(!bankDAO.value.accountNumber){
			uni.showModal({
				title:"提示",
				content:"请输入银行卡号",
				showCancel:false
			})
			return false;
		}
		if(!bankDAO.value.name){
			uni.showModal({
				title:"提示",
				content:"请输入持卡人姓名",
				showCancel:false
			})
			return false;
		}
		if(!bankDAO.value.password){
			uni.showModal({
				title:"提示",
				content:"请输入交易密码",
				showCancel:false
			})
			return false;
		}
		const result = await setBankInfo(bankDAO.value)
		if(result.code==200){
			uni.showModal({
				title:"提示",
				content:"修改成功",
				showCancel:false,
				success: () => {
					uni.navigateBack()
				}
			})
		}
	}
</script>

<style lang="scss">
	.btn{
		width: 673rpx;
		height: 100rpx;
		background: #0265FF;
		box-shadow: 0px 12rpx 23rpx 2rpx rgba(0,0,0,0.16);
		border-radius: 71rpx ;
		margin: 0 auto 38rpx;
		border: none;
		color: #fff;
		font-weight: 800;
		font-size: 38rpx;
		line-height: 100rpx;
	}
	.title{
		display: block;
		margin: 50rpx 0 77rpx 38rpx;
		color: #999;
		font-size: 27rpx;
	}
	.inp{
		width: 519rpx;
		height: 100rpx;
		background: #F6F6FF;
		border-radius: 71rpx;
		display: block;
		margin: 38rpx;
		padding: 0 77rpx;
	}
	.phl{
		color: #999;
		font-size: 28rpx;
	}
page {
		// background: #F6F7F9;
	}
</style>
